import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

// 将 request 方法, 挂载到原型上
import request from './utils/request'
Vue.prototype.$request = request

// directive自定义指令
import * as directives from '@/directives/index'
// 1.遍历得到的对象, 批量进行自定义指令的注册
// for (const key in directives) {
// key就是指令名，directives[key]对应的指令对象信息
//   Vue.directive(key, directives[key])
// }

// 2.批量注册用 Object.keys (推荐) 采用 Object.keys 得到一个对象键的数组,进行遍历处理
Object.keys(directives).forEach(key => {
  // console.log(key, directives[key])
  Vue.directive(key, directives[key])
})

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
